function zhdFenbu(xmin,ymin,xmax,ymax){
	
	var param = {
		"region":"420000",///行政区
		"zhdType":"",//灾害类型
		"zhdGroupType":"", //灾害分组
		"graphParam":xmin+","+ymin+","+xmax+","+ymax//图形范围
	}
	var sUrl = "findJbqk01ListByAdvanceCondition.shtml";
	$.post(sUrl,param,cbZhdFenbu)
}
function cbZhdFenbu(response){
	//map.events.unregister('moveend', map,mapMoveEndEventCallback);
	addMarkAndPopup(response.rows);
	//map.events.register('moveend', map,mapMoveEndEventCallback);
}

function init(){
	//添加移入用户，出现信息
	$(".forUserInfoYincang").hide();
	$("#userDiv").hover(function(){
		$(".forUserInfoYincang").show();
	},function(){
		$(".forUserInfoYincang").hide();
	}); 
	//加载一级功能菜单
	$("#sFuncBar").append(smallFunctionBarHTML);
	//如果用户是管理员，那么将“系统维护按钮”变成可点击
	 var role = $("#roleName")[0].innerHTML;
	 if(role=="管理员"){
	 	$(".xtwhBtn").click(intoQXGL);
	 }else{
		 $(".xtwhBtn").attr("class","xtwhBtnUnClick");
	 } 
	//将一级功能菜单项的按钮添加监听
	sfuncBarInit();
	//将搜索功能条加载，bfuncbar。
	$("#bFuncBar").append(bigFunctionBarHTML);
	//将搜索功能条的按钮激活
	bfuncBarInit();
	
	
	//初始化mapChangeBar
	mapChangeBarInit();
	//加载图例板
	loadLegendPanel();
	//将图例板的功能激活
	legendPanelInit();
	//加载二级菜单
	loadSecondaryFuncBar();
	//登录的人员的名字
	 var curName = $("#userDiv")[0].innerHTML;
	 isThisOneDuty(curName);
	 //加载地图
	loadMap();
	//地图放大缩小事件的监控
	mapEvtInit();
	//mapMoveEndEventCallback();

}

function loadMap(){
    //给map赋高度
	$("#map").css("height",(document.documentElement.clientHeight-150)+"px");
	var navigation = new OpenLayers.Control.Navigation();
	/////////////////////////////测试代码////////////////////
	
	/*
	 * 
	map = new OpenLayers.Map('map', {
		二调湖北省范围        maxExtent: new OpenLayers.Bounds(12015232.8263977,3153569.83612004, 12975150.725167,4113487.73488936),		郭工提供湖北省范围        maxExtent: new OpenLayers.Bounds(12059669.8263977,3376923.83612004, 12931040.725167,3934443),
        controls: [navigation],
        projection:"EPSG:102113"
    });
	layer = new OpenLayers.Layer.ArcGIS93Rest("Hubei",'http://localhost/ArcGIS/rest/services/420000/MapServer/export',{}, { singleTile: true,isBaseLayer: true });
    map.addLayer(layer);
    map.zoomToMaxExtent();*/
    
///////////////////////////////////////////////////
	 map = new OpenLayers.Map('map', {
        maxExtent: new OpenLayers.Bounds(-20037508.3427892 ,-20037508.3427892 ,20037508.3427892 ,20037508.3427892),
        maxResolution: 156543,
        controls: [navigation],
        projection:"EPSG:102113"
    });
	layer = new OpenLayers.Layer.ArcGIS93Rest("Hubei",'http://localhost/ArcGIS/rest/services/420000/MapServer/export',{}, { singleTile: true,isBaseLayer: true });
    map.addLayer(layer);
    map.zoomToMaxExtent();
   	//setEDYXLayers();
    map.setCenter(new OpenLayers.LonLat(12799839.008522447,3551570.0822424218), 6);
}
function mapMoveEndEventCallback(){
	map.events.unregister('moveend', map,mapMoveEndEventCallback);
	var levelTmp = 12;
    var x = map.getZoom();
    var bound = map.getExtent();
    var left = bound.left;
	var right = bound.right;
	var bottom = bound.bottom;
	var top = bound.top;
	var min = Mercator2lonLat(left,bottom);
	var max = Mercator2lonLat(right,top);
	var tmp_x = (max.x-min.x)/80;
	var tmp_y =(max.y-min.y)/80;
	var xmin = min.x+tmp_x;
	var ymin = min.y+tmp_y;
	var xmax = max.x-tmp_x;
	var ymax = max.y-tmp_y;
    if(x<levelTmp){
    	loadZhdByType(xmin,ymin,xmax,ymax);//将图例板切换到灾害分布图例板  崔艺 20130127        
    }else {
		zhdFenbu(xmin,ymin,xmax,ymax);
		//t2 = setTimeout("moverCar()", gpsTimeOut);
    }
   
}

// 初始化slider控件
$(function(){
	
	var sliderOpts = {
		min: 0,
		max: 100,
		range:'min',
		orientation:'vertical',
		value:100,
		step:1,
		slide: function(e, ui) {  
			var val = ui.value/100;
			setLayeOptictyChange(val);
		}
	};
	$("#slider").slider(sliderOpts);
});

function setLayeOptictyChange(val){
	if(floatlayer!=null){
		floatlayer.setOpacity(val);
	}
}

//地图放大缩小控件的事件
function mapEvtInit(){
	var zoomInControl = new OpenLayers.Control.ZoomBox({map:map});
	zoomInControl.draw();
	map.addControl(zoomInControl);
	var zoomOutControl = new OpenLayers.Control.ZoomBox({map:map,  out: true});
	zoomOutControl.draw();
	map.addControl(zoomOutControl);
	var panControl = new OpenLayers.Control.DragPan({ map: map });
	map.addControl(panControl);
	//放大
	$('#zoomIn').click(function(){
		zoomOutControl.deactivate();
		panControl.deactivate();
		zoomInControl.activate();
	});
	//缩小
	$('#zoomOut').click(function(){
		zoomInControl.deactivate();
		panControl.deactivate();
		zoomOutControl.activate();
	});
	//移动
	$('#pan').click(function(){
		zoomInControl.deactivate();
		zoomOutControl.deactivate();
		panControl.activate();
	});
	//复位
	$('#restore').click(function () {
		//map.zoomToMaxExtent();
		map.setCenter(new OpenLayers.LonLat(12799839.008522447,3551570.0822424218), 6);
	});
}


//看是否是值班人员
function isThisOneDuty(name){
	var url = "isThisOneDuty.shtml";
	$.post(url,{name:name},function(res){
		if(res=="true"){//表示是值班人员
			alert("您为值班人员，开始值班！");
			loadZbjlDlg(name);
		}
	});
}
//点击退出系统
function exit()
{
    //window.history.go(window.history.length*(-1));
    window.location.replace("userUserExit.shtml");
}

//点击系统帮助
function help(){
	var url = "jsp/down_center.jsp?flag=helpfile&filename=helpfile.docx";
	window.open(url);
}

function loadZhdByType(xmin,ymin,xmax,ymax){
	var url = "findJbqk01ListByAdvanceCondition.shtml";
	var param  ={
		"region":"420000",
		"zhdGroupType":"3,4,5,6",
		"graphParam":xmin+","+ymin+","+xmax+","+ymax,//图形范围
		"zhdType":""
	}
	$.post(url,param,function(response){
		top.closeForBaseInvestigate();
		//queryBaseInvestigate();
		if(response.rows==0) {
			//alert('没有查询结果'); 
			return;
		}
		
		addMarkAndPopup(response.rows,"group");
		//1秒以后重新注册moveend事件
		setTimeout("registEvent()", 1000);
	});
}
function registEvent(){
	map.events.register('moveend', map,mapMoveEndEventCallback);
}
function loadAllPnt(){
	var url = "findJbqk01ListByAdvanceCondition.shtml";
	var param  ={
		"region":"420000",
		"zhdGroupType":"1,2,3,4,5,6",
		"graphParam":"",
		"zhdType":""
	}
	$.post(url,param,function(response){
		top.closeForBaseInvestigate();
		//queryBaseInvestigate();
		if(response.rows==0) {
			//alert('没有查询结果'); 
			return;
		}
		top.addMarkAndPopup(response.rows,"group");
	});
}
function addEDYXLayers(){
	 edyx1 = new OpenLayers.Layer.WMTS({
        name: "WMTS",
        service: "WMTS",
        request:"GetTile",
        url: "http://172.16.10.60:808/KQWebGis.ashx",
        layer: "hbyx", 
        matrixSet: "hbyx", 
		style: "",
		isBaseLayer: false
    });
    
     edyx2 = new OpenLayers.Layer.WMTS({
        name: "WMTS",
        service: "WMTS",
        request:"GetTile",
        url: "http://172.16.10.60:808/KQWebGis.ashx",
        layer: "hbjx",
        matrixSet: "hbjx",
        style: "",
        isBaseLayer: false
    });
    map.addLayers([edyx1,edyx2]);
}
function removeEdyx(){
	if(edyx1!=null){
		map.removeLayer(edyx1);
		edyx1 = null;
	}
	if(edyx2!=null){
		map.removeLayer(edyx2);
		edyx2 = null;
	}
}